let arr = [2, 3, 4, 4, 5, 6, 7, 7]
/**
 * Set
 */
console.log(Array.from(new Set(arr)))

console.log('...', [...new Set(arr)])

/**
 * includes
 */
var newArr = []
var newArr1 = []
for (let i = 0; i < arr.length; i++) {
  let value = arr[i]
  if (!newArr.includes(value)) {
    newArr.push(value)
  }
}
console.log(newArr)

/**
 * indexof
 */
for (let i = 0; i < arr.length; i++) {
  let value = arr[i]
  if (newArr1.indexOf(value) === -1) {
    newArr1.push(value)
  }
}
console.log(newArr1)

/**
 * 利用对象key
 */
let obj = {}
let arrry = []
for (var i = 0; i < arr.length; i++) {
  if (!obj[arr[i]]) {
    arrry.push(arr[i])
    obj[arr[i]] = 1
  } else {
    obj[arr[i]]++
  }
}

/**
 * filter
 */
let arrFilter = [1, 1, 2, 3]
let new1 = arrFilter.filter((item, index) => {
  return arrFilter.indexOf(item, 0) === index
})
console.log(new1)

/**
 * map
 */

let map = new Map()
let mapArr = []
for (let i = 0; i < arr.length; i++) {
  let value = arr[i]
  if (!map.has(value)) {
    map.set(value)
    mapArr.push(value)

  }
}
console.log('mapArr', mapArr)

/**
 * reduce+includes
 */

let reduceArr = arr.reduce((prev, cur) => {
  return prev.includes(cur) ? prev : [...prev, cur]
}, [])

console.log('reduceArr', reduceArr)

/**
 * 递归 元素下边递归
 */
let loopArr = [2, 2, 3, 4, 5, 5, 5, 6, 7, 7, 8]
let len = loopArr.length
function loop(index) {
  if (index >= 1) {
    if (loopArr[index] === loopArr[index - 1]) {
      loopArr.splice(index, 1)
    }
    loop(index - 1)
  }
}
loop(len - 1)
console.log('loopArr', loopArr)


